using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace LabyrinthProject
{
    class Hud
    {
        #region fields
        private Texture2D hudTexture;

        private SpriteBatch spriteBatch;
        private SpriteFont spriteFont;
        #endregion

        #region initialization
        public Hud(Texture2D hudTexture, SpriteFont spriteFont)
        {
            this.hudTexture = hudTexture;
            this.spriteBatch = new SpriteBatch(LabyrinthGame.GDevice);
            this.spriteFont = spriteFont;
        }
        #endregion

        #region methods
        public void Draw(Camera camera)
        {
            int width = LabyrinthGame.GDevice.ScissorRectangle.Width;//1200
            int height = LabyrinthGame.GDevice.ScissorRectangle.Height;//800

            float aspect = width / (float)height;
            int newHeight=(int)((width * 800 / 1200));


            LabyrinthGame.GDevice.Viewport = camera.Viewport;

            Rectangle screenRectangle;

            screenRectangle = new Rectangle(0, height - (int)(newHeight * 145 / 800f), camera.Viewport.Width, (int)(newHeight * 145 / 800f));
            spriteBatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend);
            spriteBatch.Draw(hudTexture, screenRectangle, Color.White);
            spriteBatch.End();

            float scaleFactor = width / 1200f;
            float translateFactor = (int)((width * 800 / 1200)) / 800f;
            float step = camera.Viewport.X;

            foreach (PowerUp powerUp in camera.Player.PowerUpList)
            {
                powerUp.DrawOrtho(step);

                string output = String.Format("{0:0.00}", powerUp.LifeTime);
                Vector2 fontPosition = (height - 120 * translateFactor) * Vector2.UnitY + (70 * translateFactor + step) * Vector2.UnitX;
                Vector2 fontOrigin = spriteFont.MeasureString(output) / 2;

                spriteBatch.Begin();
                spriteBatch.DrawString(spriteFont, output, fontPosition, Color.DarkGreen, 0, fontOrigin, scaleFactor, SpriteEffects.None, 0.5f);
                spriteBatch.End();

                step += 115 *camera.Viewport.Width / 600f;
            }
        }
        #endregion
    }
}
